<?php

namespace app\common\logic;



class DataLogic{

    public static function getDataList($query,array $where,$order,$field,$limit=10,$page=1,$append)

    {

        $total=$query->where($where)->count();
        if($field){
            $query = $query->field($field);
        }

        $list=$query->where($where)

            ->order($order);

        if($limit>0 && $page>0){

            $list = $list->limit($limit)->page($page);
        }

        $list = $list->select()

            ->append($append)

            ->toArray();

        if(isset($list[0]['write_off'])){

            foreach($list as $k=>$v){

                switch ($list[$k]['write_off']){

                    case 1:

                        $list[$k]['write_off'] = '已核销';

                        break;

                    case 2:

                        $list[$k]['write_off'] = '未核销';

                        break;

                    case 3:

                        $list[$k]['write_off'] = '不需要核销';

                        break;

                }

            }

        }

        return ['total'=>$total,'list'=>$list];

    }
    public static function exportList($query,array $where,$order,$field,$append)

    {
        if($field){
            $query = $query->field($field);
        }

        $list=$query->where($where)

            ->order($order)

            ->select()

            ->append($append)

            ->toArray();

        return $list;

    }

}

